package jok.charset;

import java.io.UnsupportedEncodingException;

public class StringCharsetDemo {

	public static void main(String[] args) throws UnsupportedEncodingException {

		String str = "你好";
		byte[] bsDefault = str.getBytes();// UTF-8
		byte[] bsGBK = str.getBytes("GBK");

		printBytes(bsDefault);// -28 -67 -96 -27 -91 -67
		System.out.println(new String(bsDefault));// 你好

		printBytes(bsGBK);// -60 -29 -70 -61
		System.out.println(new String(bsGBK, "GBK"));// 你好
	}

	public static void printBytes(byte[] bs) {
		for (byte b : bs) {
			System.out.print(b + " ");
		}
	}
}
